package edu.zut.main.thread;

/**
 * 利用匿名内部类或lambda表达式创建多线程
 */
public class ThreadDemo4 {

    public static void main(String[] args) {
        //利用匿名内部类
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("线程A执行......");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"线程的任务体");
            }
        },"threadA");

        //lambda表达式   针对函数式接口可以进行简化
        Thread threadB = new Thread(() -> {
            System.out.println("线程B执行");
            /*try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }*/
            System.out.println(Thread.currentThread().getName() + "线程的任务体");
        }, "threadB");

        thread.start();
        threadB.start();
    }
}
